package com.woniu.account.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.account.form.venueAdminRole.updateVenueAdminRoleForm;
import com.woniu.account.model.VenueAdminRole;
import com.woniu.account.dao.VenueAdminRoleDao;
import com.woniu.account.service.VenueAdminRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年07月11日
 */
@Service
public class VenueAdminRoleServiceImpl extends ServiceImpl<VenueAdminRoleDao, VenueAdminRole> implements VenueAdminRoleService {
    @Autowired
    private VenueAdminRoleDao venueAdminRoleDao;

    @Override
    @Transactional
    public void updateAdminRole(updateVenueAdminRoleForm form) {
        QueryWrapper<VenueAdminRole> qw = new QueryWrapper<VenueAdminRole>().eq("venue_admin_id", form.getVenueAdminId());
        List<VenueAdminRole> venueAdminRoles = venueAdminRoleDao.selectList(qw);
        if (venueAdminRoles != null && venueAdminRoles.size() != 0)
            venueAdminRoleDao.deleteBatchIds(venueAdminRoles);
        ArrayList<VenueAdminRole> venueAdminRoles1 = new ArrayList<>();
        for (Integer integer : form.getVenueRoles()) {
            VenueAdminRole venueAdminRole = new VenueAdminRole();
            venueAdminRole.setVenueAdminId(form.getVenueAdminId());
            venueAdminRole.setRoleId(integer);
            venueAdminRoles.add(venueAdminRole);
        }
        saveBatch(venueAdminRoles);
    }
}
